import { Body, Controller, Delete, HttpCode, HttpStatus, Param, ParseIntPipe, Patch, Post, UseGuards } from '@nestjs/common';
import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { RoleService } from 'src/service/role/role.service';
import { RolesDto } from './dto/roles.dto';
import { RoleListVo } from './vo/role.vo';
import { AuthGuard } from '@nestjs/passport';
@ApiTags('后台管理系统-角色管理')
@UseGuards(AuthGuard('jwt'))
@Controller('role')
export class RoleController {
    constructor(private roleService: RoleService) { }
    // 角色新增
    @ApiOperation({
        summary: '角色新增',
        description: '角色新增',
    })
    @ApiCreatedResponse({
        status: 200,
        description: '成功时返回的数据',
    })
    @Post('add')
    @HttpCode(HttpStatus.OK)
    async userAdd(@Body() rolesDto: RolesDto) {
        const message = await this.roleService.add(rolesDto)
        return message
    }
    // 角色删除
    @ApiOperation({ summary: '删除账号', description: '根据id删除账号' })
    @ApiCreatedResponse({
        type: String,
        description: '修改账号返回值',
    })
    @HttpCode(HttpStatus.OK)
    @Delete('remove/:id')
    async destroyById(@Param('id', new ParseIntPipe()) id: number): Promise<string> {
        return await this.roleService.remove(id);
    }

    //角色修改
    @ApiOperation({
        summary: '角色修改',
        description: '角色修改',
    })
    @ApiCreatedResponse({
        status: 200,
        description: '成功时返回的数据',
    })
    @HttpCode(HttpStatus.OK)
    @Patch('update/:id')
    async userUpdate(@Param('id', new ParseIntPipe()) id: number, @Body() body: RolesDto) {
        const result = await this.roleService.update(id, body)
        return result
    }
    // 角色查找
    @ApiOperation({
        summary: '用户查找',
        description: '用户查找',
    })
    @ApiCreatedResponse({
        status: 200,
        description: '成功时返回的数据',
    })
    @HttpCode(HttpStatus.OK)
    @Post('findAll')
    async userFindSelect(@Body() body: RolesDto): Promise<RoleListVo> {
        return await this.roleService.findAll(body)
    }
}
